namespace Digitalmes.Application.Sys.Dicts.Queries;

/// <summary>
/// 字典数据项分页查询命令。
/// </summary>
public record GetDictItemListWithPagedQuery(
    long DictId,
    int PageNumber,
    int PageSize) : IPagedQuery, IRequest<IResult<PagedList<SysDictItemDto>>>;

internal sealed class GetDictItemListWithPagedQueryHandler(IRepository<SysDictItem> repo) : IRequestHandler<GetDictItemListWithPagedQuery, IResult<PagedList<SysDictItemDto>>>
{
    public async Task<IResult<PagedList<SysDictItemDto>>> Handle(GetDictItemListWithPagedQuery request, CancellationToken cancellationToken)
    {
        var items = await repo.GetPagedListAsync(m => m.DictId == request.DictId, request.PageNumber, request.PageSize, cancellationToken);
        return Result.From(items.Adapt<PagedList<SysDictItemDto>>());
    }
}
